﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Model.SiteAdmin;
using Jzy.Core.Tree;
using System.Web.UI.HtmlControls;
using Jzy.Core.Utility;
using Jzy.BLL.SiteAdmin;

namespace Jzy.Web.SiteAdmin.Article
{
    public partial class MenuTree : PageBase
    {
        private string _menuID;
        private string MenuID
        {
            get
            {
                if (_menuID == null)
                {
                    if (string.IsNullOrEmpty(Request["MenuID"]))
                    {
                        _menuID =_menu.GetRootID().ToString();
                    }
                    else
                    {
                        _menuID = this.Decrypt(Request["MenuID"]);
                    }
                }
                return _menuID;
            }
        }

       
        private MenuBO _menu = new MenuBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                HtmlGenericControl body = (HtmlGenericControl)this.Master.Page.Form.FindControl("body");
                body.Attributes.Add("class", "left_body_bg");
                BindTree();
                JSUtil.SetDivHeight("tree", 30);
            }
        }

        private void BindTree()
        {
            string navigateUrl = "List.aspx?MenuID=";
            lnkRoot.NavigateUrl = navigateUrl +  StrUtil.EncryptUrl(MenuID);
            lnkRoot.Text = _menu.GetName(MenuID);

            _menu.BindTreeView(tv, null, null, int.Parse(MenuID), navigateUrl);
        }
    }
}
